package com.spzx.product.api;

import com.spzx.common.core.constant.SecurityConstants;
import com.spzx.common.core.constant.ServiceNameConstants;
import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.product.api.domain.*;
import com.spzx.product.api.domain.vo.SkuStockVo;
import com.spzx.product.api.factory.RemoteProductFallbackFactory;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;

import java.util.List;
import java.util.Map;

@FeignClient(
        contextId = "remoteProductService",
        value = ServiceNameConstants.PRODUCT_SERVICE,
        fallbackFactory = RemoteProductFallbackFactory.class
)
public interface RemoteProductService {
    @GetMapping("/product/getTopSale")
    public R<List<ProductSku>> getTopSale(@RequestHeader(SecurityConstants.FROM_SOURCE) String resource);


    @Operation(summary = "商品列表查询")
    @GetMapping("/product/skuList/{pageNum}/{pageSize}")
    public R<TableDataInfo> skuList(
            @PathVariable("pageNum") Integer pageNum,
            @PathVariable("pageSize") Integer pageSize,
            @SpringQueryMap SkuQuery skuQuery, //@SpringQueryMap这个注解作用：就是告诉openFeign构建远程调用请求，将对象数据，以路径参数的方式进行传递
            @RequestHeader(SecurityConstants.FROM_SOURCE) String source
    );

    /**
     *获取商品sku
     * @param skuId
     * @return
     */
    @Operation(summary = "获取商品sku信息")
    @GetMapping("/product/getProductSku/{skuId}")
    public R<ProductSku> getProductSku(
            @PathVariable("skuId") Long skuId,
            @RequestHeader(SecurityConstants.FROM_SOURCE)String source);

    /**
     * 获取商品信息
     * @param id
     * @return
     */
    @Operation(summary = "获取商品信息")
    @GetMapping("/product/getProduct/{id}")
    public R<Product> getProduct(
            @PathVariable("id") Long id,
            @RequestHeader(SecurityConstants.FROM_SOURCE) String source
    );

    /**
     * 获取商品sku最新价格信息
     * @param skuId
     * @return
     */
    @Operation(summary = "获取商品sku最新价格信息")
    @GetMapping(value = "/product/getSkuPrice/{skuId}")
    public R<SkuPrice> getSkuPrice(
            @PathVariable("skuId") Long skuId,
            @RequestHeader(SecurityConstants.FROM_SOURCE) String source
    );


    /**
     * 获取商品详细信息
     * @param id
     * @return
     */
    @Operation(summary = "获取商品详细信息")
    @GetMapping("/product/getProductDetails/{id}")
    public R<ProductDetails> getProductDetails(
            @PathVariable("id") Long id,
            @RequestHeader(SecurityConstants.FROM_SOURCE) String source
    );

    /**
     * 获取商品sku规则详细信息
     * @param id
     * @return
     */
    @Operation(summary = "获取商品sku规则详细信息")
    @GetMapping("/product/getSkuSpecValue/{id}")
    public R<Map<String,Long>> getSkuSpecValue(
            @PathVariable("id") Long id,
            @RequestHeader(SecurityConstants.FROM_SOURCE) String source
    );

    /**
     * 获取商品sku库存信息
     * @param skuId
     * @return
     */
    @Operation(summary = "获取商品sku库存信息")
    @GetMapping("/product/getSkuStock/{skuId}")
    public R<SkuStockVo> getSkuStock(
            @PathVariable("skuId") Long skuId,
            @RequestHeader(SecurityConstants.FROM_SOURCE) String source
    );
}
